package com.example.prison.mapper;

import com.example.prison.entity.DeviceInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author jiang
* @description 针对表【device_info】的数据库操作Mapper
* @createDate 2023-05-29 11:38:26
* @Entity com.example.prison.entity.DeviceInfo
*/
@Mapper
public interface DeviceInfoMapper extends BaseMapper<DeviceInfo> {

    @Select("select * from device_info order by device_id desc")
    List<DeviceInfo> get();

    @Insert("insert into device_info(device_name, device_number, position, type, device_status, module_address,ip,port) values (#{deviceName}, #{deviceNumber}, #{position}, #{type}, #{deviceStatus}, #{moduleAddress},#{ip},#{port})")
    int add(DeviceInfo device);

    @Delete("<script>delete from device_info where device_id in <foreach collection=\"ids\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item} </foreach> </script>")
    void deleteDevice(@Param("ids") Integer[] ids);

    @Update("update device_info set device_name=#{device.deviceName},device_number=#{device.deviceNumber},position=#{device.position},type=#{device.type},device_status=#{device.deviceStatus},module_address=#{device.moduleAddress},ip=#{device.ip},port=#{device.port} where device_id = #{deviceId}")
    int updateDevice(DeviceInfo device,Integer deviceId);

    @Update("update device_info set device_name=#{device.deviceName},device_number=#{device.deviceNumber},position=#{device.position},type=#{device.type},device_status=#{device.deviceStatus},module_address=#{device.moduleAddress},ip=#{device.ip},port=#{device.port} where device_id = #{deviceId}")
    int updateDeviceFail(DeviceInfo device,Integer deviceId);

    @Select("select * from device_info where device_id=#{deviceId}")
    DeviceInfo getById(@Param("deviceId") Integer deviceId);

    @Select("select * from device_info where device_name like concat('%',#{deviceName},'%') order by device_id desc")
    List<DeviceInfo> getByName(@Param("deviceName") String deviceName);

    @Select("select * from device_info where device_name =#{deviceName}")
    DeviceInfo getOneByName(@Param("deviceName") String deviceName);

    @Select("select * from device_info where device_number like concat('%',#{deviceNumber},'%') order by device_id desc")
    List<DeviceInfo> getByNumber(@Param("deviceNumber") String deviceNumber);

    @Select("select * from device_info where device_number=#{deviceNumber} order by device_id desc")
    DeviceInfo getOneByNumber(@Param("deviceNumber") String deviceNumber);

}




